import io
import threading

from View.WindowThread.InterfaceThread import InterfaceThread


class ThreadManager:
    def __init__(self, thread_class: InterfaceThread):
        self.thread_class = thread_class
        self.io = io.BytesIO(b"start")
        thread = threading.Thread(target=self.body)
        thread.start()


    def body(self):
        try:
            count = 0
            while True:

                ret = self.thread_class.whileBody(count)
                if ret == "break:<threadManager>":
                    break
                count += 1
                if self.io.getvalue() == b'break': break

        except Exception as e:
            raise e
        finally:
            self.io.close()

    def closeThread(self):
        self.io = self.thread_class.whileBreak(self.io)
